package com.cskaoyan.service.wxbrand;

import com.cskaoyan.bean.MallBrand;
import com.cskaoyan.bean.MallBrandExample;
import com.cskaoyan.mapper.MallBrandMapper;
import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.vo.BaseData;
import com.cskaoyan.model.vo.wxbrand.WxBrandListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: mjm
 * @Date: 2021/12/2
 * @Time: 11:37
 * @Description:
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    MallBrandMapper mallBrandMapper;

    @Override
    public BaseData brandList(PageBo pageBo) {
        PageHelper.startPage(pageBo.getPage(), pageBo.getLimit());
        MallBrandExample example = new MallBrandExample();
        //逻辑删除的不显示
        example.createCriteria().andDeletedEqualTo(false);
        List<MallBrand> mallBrands = mallBrandMapper.selectByExample(example);

        //vo与数据表字段不对应
        ArrayList<WxBrandListVo> wxBrandListVos = new ArrayList<>();
        for (MallBrand mallBrand : mallBrands) {
            WxBrandListVo wxBrandListVo = new WxBrandListVo();
            wxBrandListVo.setDesc(mallBrand.getDesc());
            wxBrandListVo.setId(mallBrand.getId());
            wxBrandListVo.setName(mallBrand.getName());
            wxBrandListVo.setPicUrl(mallBrand.getPicUrl());
            wxBrandListVo.setFloorPrice(mallBrand.getFloorPrice());
            wxBrandListVos.add(wxBrandListVo);
        }

        PageInfo info = new PageInfo(wxBrandListVos);
        long total = info.getTotal();
        return BaseData.list(wxBrandListVos,total);
    }

    @Override
    public MallBrand brandDetail(Integer id) {

        MallBrand mallBrand = mallBrandMapper.selectByPrimaryKey(id);
        return mallBrand;
    }
}
